package com.top.up.core.config.redis;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

@Component
public class RedisCommand {

    @Autowired
    private RedisTemplate<String, Object> redisTemplate;

    public void set(String key, Object obj, long minutes) {
        redisTemplate.opsForValue().set(key, obj, minutes, TimeUnit.SECONDS);
    }

    public void set(String key, Object obj) {
        redisTemplate.opsForValue().set(key, obj);
    }

    public <T> T get(String key) {
        return (T)redisTemplate.opsForValue().get(key);
    }

    public void del(String key) {
        redisTemplate.delete(key);
    }

    public Long expire(String key){
        return redisTemplate.getExpire(key);
    }

}
